import axios from '@/libs/api.request'

export const login = ({ userName, password }) => {
  const data = {
    account: userName,
    password: password
  }
  return axios.request({
    url: 'login',
    data,
    method: 'post'
  })
}

export const getUserInfo = (token) => {
  return axios.request({
    url: 'get_info',
    query: {
      token
    },
    method: 'get'
  })
}

export const logout = (token) => {
  return axios.request({
    url: 'logout',
    method: 'post'
  })
}

export const getUnreadCount = () => {
  return axios.request({
    url: 'message/count',
    method: 'get'
  })
}

export const getMessage = () => {
  return axios.request({
    url: 'message/init',
    method: 'get'
  })
}

export const getContentByMsgId = msg_id => {
  return axios.request({
    url: 'message/content',
    method: 'get',
    query: {
      msg_id
    }
  })
}

export const hasRead = msg_id => {
  return axios.request({
    url: 'message/has_read',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const removeReaded = msg_id => {
  return axios.request({
    url: 'message/remove_readed',
    method: 'post',
    data: {
      msg_id
    }
  })
}

export const restoreTrash = msg_id => {
  return axios.request({
    url: 'message/restore',
    method: 'post',
    data: {
      msg_id
    }
  })
}

/**
 * 获取用户列表
 */
export const getUserList = ({ name, mobile, pageId = 1, adminId }) => {
  const data = {
    name,
    mobile,
    pageId,
    adminId
  }
  return axios.request({
    url: '/User/getUserList',
    method: 'post',
    data
  })
}

/**
 * 获取用户详情
 */
export const getUserDetail = ({cid, adminId}) => {
  return axios.request({
    url: 'User/getUserDetail',
    method: 'post',
    data: { cid, adminId }
  })
}

/**
 * 修改用户详情
 */
export const editUser = ({ id, channelSrc, mobile, name, bankCardUserName, bankCardNumber, bank, managerName, managerMobile, adminId }) => {
  const data = {
    cid: id,
    channelSrc,
    mobile,
    name,
    bankCardUserName,
    bankCardNumber,
    bank,
    managerName,
    managerMobile,
    adminId
  }
  return axios.request({
    url: 'User/editUser',
    method: 'post',
    data
  })
}

/**
 * 获取客户经理
 */
export const getAdmin = () => {
  return axios.request({
    url: 'User/getAdmin',
    method: 'post',
  })
}

/**
 * 我的客户
 */
export const getLoanApplicationList = ({cid,name,applyMobile,status}) => {
  return axios.request({
    url: 'User/getLoanApplicationList',
    method: 'post',
    data: {cid,name,applyMobile,status}
  })
}

/**
 * 我的客户详情
 */
export const getLoanApplicationDetail = ({id, cid}) => {
  return axios.request({
    url: 'User/getLoanApplicationDetail',
    method: 'post',
    data: {id, cid}
  })
}

/**
 * 修改贷款申请记录
 */
export const editLoanApplication = ({id, status, loanAmount, reward, leaderReward, cid}) => {
  const data = { id, status, loanAmount, reward, leaderReward, cid }
  return axios.request({
    url: 'User/editLoanApplication',
    method: 'post',
    data
  })
}

/**
 * 添加佣金
 */
// export const addReward = ({rewardType, cid, id, reward, leaderReward}) => {
//   return axios.request({
//     url: 'User/addReward',
//     method: 'post',
//     data: {rewardType, cid, id, reward, leaderReward}
//   })
// }

/**
 * 获取跟进记录
 */
export const getRecordList = ({loanApplicationId ,pageId}) => {
  return axios.request({
    url: 'User/getRecordList',
    method: 'post',
    data: {loanApplicationId ,pageId}
  })
}

/**
 * 添加跟进记录
 */
export const addRecord = ({loanApplicationId, content}) => {
  return axios.request({
    url: 'User/addRecord',
    method: 'post',
    data: {loanApplicationId, content}
  })
}

/**
 * 删除跟进记录
 */
export const delRecord = (id) => {
  return axios.request({
    url: 'User/delRecord',
    method: 'post',
    data: {id}
  })
}

/**
 * 我的团队
 */
export const getUserTeam = ({cid,name,pageId,adminId}) => {
  return axios.request({
    url: 'User/getUserTeam',
    method: 'post',
    data: {cid,name,pageId,adminId}
  })
}

/**
 * 删除团队成员
 */
export const delUserTeam = (cid) => {
  return axios.request({
    url: 'User/delUserTeam',
    method: 'post',
    data: {cid}
  })
}


/**
 * 查看下级客户
 */
export const getTeamApplication = ({cid,name,pageId}) => {
  return axios.request({
    url: 'User/getTeamApplication',
    method: 'post',
    data: {cid,name,pageId}
  })
}

/**
 * 获取佣金变更
 */
export const getLogReward = ({cid,id,sourceSrc}) => {
  return axios.request({
    url: 'User/getLogReward',
    method: 'post',
    data: {cid,id,sourceSrc}
  })
}

/**
 * 修改密码
 */
export const editPassword = ({cid,password}) => {
  return axios.request({
    url: 'User/editPassword',
    method: 'post',
    data: {cid,password}
  })
}

/**
 * 后台修改佣金
 */
export const editReward = ({cid,sign,money}) => {
  return axios.request({
    url: 'User/editReward',
    method: 'post',
    data: {cid,sign,money}
  })
}
